﻿@model CREAPA.Dominio.OS
@{
    ViewBag.Title = "RegistrarAtendimento";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="~/Scripts/js/original/InputMask.js"></script>
     <script src="~/Scripts/js/JavaScriptUtil.js"></script>

<script type="text/javascript">
    function setup() {
        new SizeLimit("Descricao", 1000, "DescricaoOut", "${size} / ${max}");
        new SizeLimit("DescricaoAnalise", 1000, "DescricaoAnaliseOut", "${size} / ${max}");
        document.getElementById("TempoExec").innerText = TempoExec.value = 0;
    }
</script>
<style>
		
		* {
			margin: 0;
			padding: 0;
		}

        fieldset.grupo {
			border: 0;
		}

		
		body, input, select, textarea, button {
			font-family: sans-serif;
			font-size: 1em;
		}

		.grupo:after {
			content: "."; 
			display: block; 
			height: 0;
			clear: both; 
			visibility: hidden;
            
		}

		.campo {
			margin-bottom: 1em;
		}
        
        .campo label {
			margin-bottom: 0.2em;
			color: #000;
			display: block;
            margin-left: 3px;
		}
        
		fieldset.grupo .campo {
			float: left;
			margin-right: 3em;
            margin-left: 3px;
		}

		.campo input[type="text"],
		.campo input[type="email"],
		.campo input[type="url"],
		.campo input[type="tel"] {
			padding: 0.2em;
			border: 1px solid #CCC;
			box-shadow: 2px 2px 2px rgba(0,0,0,0.2);
			display: block;
            width: 200%;
            margin-left: 3px;
		}
        .campo textarea {
			padding: 0.2em;
			border: 1px solid #CCC;
			box-shadow: 2px 2px 2px rgba(0,0,0,0.2);
			display: block;
            width: 525px;
            margin-left: 3px;
		}

		.campo select option {
			padding-right: 1em;
		}

		.campo input:focus, .campo select:focus, .campo textarea:focus {
			background: #ffffff;
		}

		.campo label.checkbox {
			color: #000;
			display: inline-block;
			margin-right: 1em;
		}
	
	</style>

<script language=JavaScript>
<!-- begin
    var sHors = "0" + 0;
    var sMins = "0" + 0;
    var sSecs = 0;
    function getSecs(c) {
        sSecs++;
        if (sSecs == 60) {
            sSecs = 0; sMins++;
            if (sMins <= 9) sMins = "0" + sMins;
        }
        if (sMins == 60) {
            sMins = "0" + 0; sHors++;
            if (sHors <= 9) sHors = "0" + sHors;
        }
        if (sSecs <= 9) sSecs = "0" + sSecs;
        clock1.innerHTML = sHors + "<font color=#000000>:</font>" + sMins + "<font color=#000000>:</font>" + sSecs;
        setTimeout('getSecs()', 1000);
    }
    var c = false;
    function ok(d){
        if (d.checked) {
            c = true;
        } else {
            c = false;
            document.getElementById("TempoExec").innerText = TempoExec.value = 0;
            document.getElementById("TempoUnidade").innerText = TempoUnidade.value = "M";
        }
       }
    function TempAutomatico(c) {
            if (c==true) {
                if (sHors >= 1) {
                    document.getElementById("TempoExec").innerText = TempoExec.value = sHors;
                    document.getElementById("TempoUnidade").innerText = TempoUnidade.value = "H";
                } else {
                    if (sMins >= 1) {
                        document.getElementById("TempoExec").innerText = TempoExec.value = sMins;
                        document.getElementById("TempoUnidade").innerText = TempoUnidade.value = "M";
                    } else {
                        if (sSecs >= 1) {
                            document.getElementById("TempoExec").innerText = TempoExec.value = sSecs;
                            document.getElementById("TempoUnidade").innerText = TempoUnidade.value = "S";
                        }
                    }
                }
            } 
            setTimeout('TempAutomatico(c)', 1000);
    }
    //-->
</SCRIPT>


<h2>Registrar Atendimento</h2>

@using (Html.BeginForm("RegistrarAtendimento", "OS", FormMethod.Post,
          new { enctype = "multipart/form-data" })) {
 @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
<body onload="setup()">
    <fieldset>
        <legend>OS</legend>        
      
     <fieldset class="grupo">
        <div class="login-msg">
            <div class="campo">   
        @Html.LabelFor(model => model.GrupoProblema)
        @Html.DropDownListFor(
    x => x.GrupoProblema, 
    new SelectList(ViewBag.GrupoProblema, "Value", "Text"),
    "-- SELECIONE O GRUPO DO PROBLEMA --")
        
        </div>
        <div class="login-msg">
        <div class="campo">
            @Html.LabelFor(model => model.Problema)
            @Html.DropDownListFor(
    model => model.Problema, 
    Enumerable.Empty<SelectListItem>(),
    "-- SELECIONE O PROBLEMA --") 
            @Html.ValidationMessageFor(model => model.Problema) </div></div>
    </div>
            
         </fieldset>
       
       <fieldset class="grupo"> 
        <div class="login-msg">
        <div class="campo" id="Tempo">
            @Html.LabelFor(model => model.TempoExec)
            @Html.EditorFor(model => model.TempoExec, new {@value='0'})
            @Html.ValidationMessageFor(model => model.TempoExec)
            @Html.DropDownListFor(model => model.TempoUnidade,
                      new SelectList(new List<SelectListItem> {
                      new SelectListItem{Value="M", Text="Minuto"},                           
                      new SelectListItem{Value="S", Text="Segundo"},                           
                           new SelectListItem{Value="H", Text="Hora"},
                           new SelectListItem{Value="D", Text="Dia"}}, "Value", "Text"))
            @Html.ValidationMessageFor(model => model.TempoUnidade)
             <font color="#FF0000"><span id="clock1"></span><script>setTimeout('getSecs()', 1000);</script></font>
                <script>setTimeout('TempAutomatico()', 1000);</script>
</div>      
            <div class="campo" id="TempAuto">
            <label>Tempo Automático</label>
            <input type="checkbox"onclick="ok(this);">    
            </div>  </div>      
        <div class="login-msg">
        <div class="campo">
            @Html.LabelFor(model => model.PessoaInteressado)
            @Html.DropDownList("PessoaInteressado","Selecione")
            @Html.ValidationMessageFor(model => model.PessoaInteressado)
        </div>
        <div class="campo">
            @Html.LabelFor(model => model.OrigemOS)
            @Html.DropDownList("OrigemOS",  "Selecione")      
            @Html.ValidationMessageFor(model => model.OrigemOS)
</div>
        <div class="campo">
            <Label Id="AnalisadaL">Analisada</Label>              
             @Html.CheckBoxFor(model => model.Analisada, new { @checked = "checked" })
</div>     
        <div class="campo">
            <Label Id="EncerradaL">Encerrada</Label>
             @Html.CheckBoxFor(model => model.Encerrada, new { @checked = "checked" })
        </div>
        </fieldset>
         
        <fieldset class="grupo"> 
        <div class="login-msg">
        <div class="campo">
            @Html.LabelFor(model => model.Descricao)
            @Html.TextAreaFor(model => model.Descricao)@*,new{id = "body", rows = "3", htmlEncodeOutput="true", maxlength = "500"})*@
            @Html.ValidationMessageFor(model => model.Descricao)
            <div style="text-align:right;">
             <label id="DescricaoOut"></label>
        </div>
</div>
        <div class="login-msg">
        <div class="campo">
            <Label Id="DescricaoAnalise">Descrição de Análise</Label>                
            @Html.TextAreaFor(model => model.DescricaoAnalise)@*, new{id = "body", rows = "3", htmlEncodeOutput="true", maxlength = "500"})*@
            @Html.ValidationMessageFor(model => model.DescricaoAnalise)
            <div style="text-align:right;">
             <label id="DescricaoAnaliseOut"></label>
        </div>
</div>     
       
 </fieldset>
            <fieldset class="grupo"> 
            <div class="campo">
            <label>Cadastrar OS</label>
            <input type="checkbox"onclick="showT(this, this.form);">    
            </div>        
            <div class="campo">
            <Label Id="SetorL" style="visibility:hidden">Setor de Destino</Label>
            <div class="login-msg" style="visibility:hidden">
            @Html.DropDownList("Setor",  "Selecione")
            @Html.ValidationMessageFor(model => model.Setor)
            </div> </div>
            
            </fieldset>
            <div>
            <Label Id="DescAnexoL" style="display:none">Descrição do Documento Anexado (Não obrigatório):</Label>
            <div class="login-msg" style="display:none" id="anexonome">
            @Html.TextAreaFor(model => model.Anexo.Nome, new { style = "width: 530px;", rows ="1"})
            @Html.ValidationMessageFor(model => model.Anexo.Nome)   
            </div>     
            <input type="file" name="FileUpload1" style="display:none" />
            </div>
            
        <p>
            <input type="submit" value="Cadastrar" class="button" />
            @Html.ActionLink("Voltar", "Index",null,new { @class = "button2" })
        </p>
    
        
    </fieldset>
    </body>
<script>
    jQuery(document).ready(function () {
        // verifica se existe algum elemento com a class
        if ($(".button").length) {
            // adiciona evento desabilitando o botão
            $(".button").on('click', function () {
                $(this).attr({
                    disabled: true
                });
                // descobrindo o form pai e enviando
                this.value = 'Enviando...';
                $(this).parents('form:first').submit();
            });
        }
    });
</script>

            <script>
                function disaT(c, f) {
                    if (c.checked) { f.txt1.disabled = false }
                    else { f.txt1.disabled = true }
                }
                function showT(c, f) {
                    if (c.checked) {
                        f.Setor.style.visibility = "visible";
                        document.getElementById("SetorL").innerText = SetorL.style.visibility = "visible";
                        document.getElementById("Analisada").innerText = Analisada.style.visibility = "hidden", Analisada.checked=null;
                        document.getElementById("Encerrada").innerText = Encerrada.style.visibility = "hidden", Encerrada.checked = null;
                        document.getElementById("AnalisadaL").innerText = AnalisadaL.style.visibility = "hidden";
                        document.getElementById("EncerradaL").innerText = EncerradaL.style.visibility = "hidden";
                        f.DescricaoAnalise.style.display = "none"
                        document.getElementById("DescricaoAnalise").innerText = DescricaoAnalise.style.display = "none"; 
                        document.getElementById("DescAnexoL").innerText = DescAnexoL.style.display = "block";
                        document.getElementById("Anexo_Nome").innerText = Anexo_Nome.style.visibility = "visible";
                        document.getElementById("anexonome").innerText = anexonome.style.display = "block";
                        document.getElementById("TempAuto").innerText = TempAuto.style.display = "none";
                        document.getElementById("Tempo").innerText = Tempo.style.display = "none";
                        document.getElementById("DescricaoOut").innerText = DescricaoOut.style.display = "none";
                        document.getElementById("DescricaoAnaliseOut").innerText = DescricaoAnaliseOut.style.display = "none";
                        f.FileUpload1.style.display = "block";
                    }
                    else {
                        f.Setor.style.visibility = "hidden";
                        document.getElementById("SetorL").innerText = SetorL.style.visibility = "hidden";
                        document.getElementById("Analisada").innerText = Analisada.style.visibility = "visible", Analisada.checked = true;
                        document.getElementById("Encerrada").innerText = Encerrada.style.visibility = "visible", Encerrada.checked = true;
                        document.getElementById("AnalisadaL").innerText = AnalisadaL.style.visibility = "visible";
                        document.getElementById("EncerradaL").innerText = EncerradaL.style.visibility = "visible";
                        f.DescricaoAnalise.style.display = "block"
                        document.getElementById("DescricaoAnalise").innerText = DescricaoAnalise.style.display = "block";
                        document.getElementById("DescAnexoL").innerText = DescAnexoL.style.display = "none";
                        document.getElementById("Anexo_Nome").innerText = Anexo_Nome.style.visibility = "hidden";
                        document.getElementById("anexonome").innerText = anexonome.style.display = "none";
                        document.getElementById("TempAuto").innerText = TempAuto.style.display = "block";
                        document.getElementById("Tempo").innerText = Tempo.style.display = "block";
                        document.getElementById("DescricaoOut").innerText = DescricaoOut.style.display = "block";
                        document.getElementById("DescricaoAnaliseOut").innerText = DescricaoAnaliseOut.style.display = "block";
                        f.FileUpload1.style.display = "none";
                    }
                }
                
</script>
}


<script type="text/javascript">
    $('#GrupoProblema').change(function () {
        var selectedGrupoProblema = $(this).val();
        if (selectedGrupoProblema != null && selectedGrupoProblema != '') {
            $.getJSON('@Url.Action("GetProblemas")', { grupo: selectedGrupoProblema }, function (problemas) {
                var problemasSelect = $('#Problema');
                problemasSelect.empty();
                $.each(problemas, function (index, problema) {
                    problemasSelect.append($('<option/>', {
                        value: problema.Value,
                        text: problema.Text
                    }));
                });
            });
        }
    });
</script>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

